<template>
  <div class="login-phone">
    <el-form label-width="80px" class="demo-ruleForm" :model="phone" :rules="rules" ref="elFormRef">
      <el-form-item label="手机号码" prop="pnumber">
        <el-input v-model="phone.pnumber"></el-input>
      </el-form-item>
      <el-form-item label="验证码" prop="pcode">
        <div class="item-pcode">
          <el-input v-model="phone.pcode"></el-input>
          <el-button type="primary" class="btn-code">获取验证码</el-button>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
import { ElForm } from 'element-plus'

export default defineComponent({
  setup() {
    const phone = reactive({
      pnumber: '',
      pcode: ''
    })
    const rules = reactive({
      pnumber: [
        {
          type: 'number',
          required: true,
          message: '请输入手机号码',
          trigger: 'change'
        },
        {
          max: 11,
          message: '手机号长度不能超过11位',
          trigger: 'blur'
        }
      ],
      pcode: [
        {
          required: true,
          message: '请输入验证码',
          trigger: 'change'
        }
      ]
    })
    const elFormRef = ref<InstanceType<typeof ElForm>>()
    const loginAction = () => {
      // console.log('执行phonelogin动作')
      elFormRef.value?.validate((valid) => {
        console.log(valid)
      })
    }
    return { phone, rules, elFormRef, loginAction }
  }
})
</script>

<style scoped lang="less">
.item-pcode {
  display: flex;
  .btn-code {
    margin-left: 8px;
  }
}
</style>
